const http = require('http');
const app = http.createServer((req,res)=>{

    // console.log(req.url);// /list?name=laowang&age=18
    // let str = req.url.split('?')[0];
    // console.log(str);

    // 参数1：req.url
    // 参数2：http://主机地址
    let obj = new URL(req.url,"http://localhost");

    console.log(obj.searchParams.get('age')); 

    // URL {
    //     href: 'http://localhost/list',
    //     origin: 'http://localhost',
    //     protocol: 'http:',
    //     username: '',
    //     password: '',
    //     host: 'localhost',
    //     hostname: 'localhost',
    //     port: '',
    //     pathname: '/list',
    //     search: '',
    //     searchParams: URLSearchParams {},
    //     hash: ''
    //   }

    if(obj.pathname === '/list'){
        res.end('liebiao ye')
    }

    let id= 666;

    if(obj.pathname === '/'){
        res.setHeader('content-type','text/html;charset=utf-8')
        res.end('<a href="/list?id='+id+'">列表页</a>')
    }

    // console.log(obj.searchParams.get('name'));
    // console.log(obj.searchParams.get('age'));

});
app.listen(80,()=>{
    console.log("启动成功");
})